package cn.boy.web.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.boy.domain.Adminstrator;
import cn.boy.service.AdminstratorService;
import cn.boy.service.AdminstratorServiceFactory;
import cn.boy.utils.Util;

import com.sun.org.apache.commons.beanutils.BeanUtils;

public class AdminstratorRegisterServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		Map map =request.getParameterMap();
		
		try {
			if (!Util.isEmpty(map)) {
				Adminstrator admin = new Adminstrator();
				BeanUtils.populate(admin, map);
				System.out.println("admin --->>" + admin);
				AdminstratorServiceFactory instance = AdminstratorServiceFactory
						.getInstance();
				AdminstratorService service = instance.getAdminstratorService();
				service.register(admin);
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}

		
		}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
